﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using SysyemLogDome.Common;

namespace SysyemLogDome
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Application.Current.DispatcherUnhandledException += Application_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.Current.Dispatcher.UnhandledException +=
                new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
            Logging.LoggedExceptionOccurred += (o, e1) => ShowException(e1);
            Logging.OpenLogFile(AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine("日志写入测试");
        }

        private void ShowException(Exception exception)
        {
            while (exception.InnerException != null)
                exception = exception.InnerException;
            MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK);
        }

        private void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
          
        }

        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
        }

        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
        }
    }
}
